from django.db import models

# 默认的表名: booktest_bookinfo
# 如果自己制定了表名, 则使用自己的. tb_books

# 在这里定义模型类:
class BookInfo(models.Model):
    # 写字段的信息:
    # 字段名 = 字段的类型(该字段的约束)

    # 名称
    btitle = models.CharField(max_length=10)
    # 发布日期
    bpub_date = models.DateField()
    # 阅读量
    bread = models.IntegerField(default=0)
    # 评论量
    bcomment = models.IntegerField(default=0)
    # 逻辑删除
    is_delete = models.BooleanField(default=False)

    class Meta:
        # 指定表名:
        db_table = 'tb_books'

    def __str__(self):
        return self.btitle

# 定义英雄模型类 HeroInfo
class HeroInfo(models.Model):
    GENDER_CHOICES = (
        (0, 'female'),
        (1, 'male')
    )

    hname = models.CharField(max_length=20)
    hgender = models.SmallIntegerField(choices=GENDER_CHOICES, default=0)
    hcomment = models.CharField(max_length=200, null=True)

    hbook = models.ForeignKey(BookInfo, on_delete=models.CASCADE)

    is_delete = models.BooleanField(default=False)

    class Meta:
        db_table = 'tb_heros'

    def __str__(self):
        return  self.hname





